package lapsnake.ui;

import java.io.File;
import java.util.HashMap;

import javax.swing.ImageIcon;


public class IconLib
	{
	private static HashMap<String,ImageIcon> map = new HashMap<String,ImageIcon>();
	
	/**Finds the icon with the given file name. The folder and png extension should be omitted from the parameter.
	 * Avoids loading any icons twice. If name is null, this returns null.*/
	public static synchronized ImageIcon get(String name)
		{
		if(name == null)
			return null;
		ImageIcon result = map.get(name);
		String file = "icons/"+name+".png";
		if(result==null && new File(file).exists())
			{
			result = new ImageIcon(file);
			map.put(name, result);
			}
		return result;
		}
	}
